/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queryOpt;

import java.io.*;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

    String s2="config.txt";
    String s1="query.txt";
        config.SetParameter(s2);
        try {
            FileReader fr = new FileReader(s1);
            BufferedReader br = new BufferedReader(fr);
            String s = br.readLine();
            ArrayList<Double> al = new ArrayList<Double>();
            ArrayList<subPlan> plans = new ArrayList<subPlan>();
            ArrayList <ArrayList<Double>> selectSet = new ArrayList<ArrayList<Double>> ();
            al.clear();
            StringTokenizer st;
            int count = 0;
            while (s != null) {
                count++;
                ArrayList<Double> a2 = new ArrayList<Double>();
                st = new StringTokenizer(s);
                while (st.hasMoreTokens()) {
                    //al.add(Double.valueOf(st.nextToken()));
                    a2.add(Double.valueOf(st.nextToken()));
                }
                /*DP algorithm*/
                planSet optPlanSet = new planSet(a2.size());  //for each query, create a planset.stores all the subplans. Finally, the last one will be the optimal plan after DP algorithms.
                optPlanSet.initSubSet(a2);                    //initialization of all subplans for this query using selectivity arraylist,config statistics.
                subPlan optPlan = optPlanSet.DPCalculation(); //DP algorithm and finally get optimal plans.
                plans.add(optPlan);                           //add the optimal plan to planset, which stores an optimal plan for each query.
                selectSet.add(a2);
                //System.out.println(optPlan.getSeq());
                System.out.println(a2);
                //al.clear();
                s = br.readLine();
            }
            //Show the result of optimal plans
            
            showPlans show=new showPlans();
            
            show.showPlans(plans); //plans stores all optimal plans for different queries.

            show.show(selectSet);           //show
System.out.println("prontout");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

    }
}
